//
//  LGReportDetailPCIController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/2.
//  PCI报告

#import "LGReportDetailPCIController.h"

#import "LGGetWebViewController.h"
#import "LGRecordHospitalCell.h"
#import "LGReportDetailContentCell.h"
//支架信息
#import "LGReportHolderHeaderView.h"
#import "LGReportHolderFooterView.h"
#import "LGReportHolderCell.h"

#import "LGReportDetailFileCell.h"
#define viewHeight  (Screen_H-topBarHeight-viewPix(120))

@interface LGReportDetailPCIController ()<UITableViewDataSource,UITableViewDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;

/**   */
@property (nonatomic , strong)NSString *filePath;
/**   */
@property (nonatomic , strong)NSArray *titleArray;
/**   */
@property (nonatomic , strong)NSArray *keyArray;
/**  支架 */
@property (nonatomic , strong)NSArray *holderArray;

@end

@implementation LGReportDetailPCIController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
}

-(void)setType:(NSString *)type{
    _type = type;
    if([type isEqualToString:@"502"]){
        self.keyArray = @[@"cag_result",@"note"];
        self.titleArray = @[@"冠脉造影结果",@"注意事项"];
        
    }else if ([type isEqualToString:@"503"]){
        self.keyArray = @[@"findings",@"conclusion"];
        self.titleArray = @[@"造影所见",@"结论"];
        
    }else{
        self.keyArray = @[];
        self.titleArray = @[];
    }
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.holderArray = dataDic[@"zhij"];
    self.filePath = LGNSString(dataDic[@"report_file"]);
    [self.tableView reloadData];
}

-(void)checkFileInformation:(UIButton *)sender{
    LGGetWebViewController *controller = [[LGGetWebViewController alloc]init];
    controller.navigationView.title = self.dataDic[@"report_name"];
    controller.urlStr = self.filePath;
    [self.navigationController pushViewController:controller animated:YES];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return self.titleArray.count;
    }else if (section == 1){
        return self.holderArray.count;
    }else{
        return self.filePath.length>0?1:0;
    }
}

/*
 
 */
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        LGReportDetailContentCell *contentCell = [tableView dequeueReusableCellWithIdentifier:@"contentCell" forIndexPath:indexPath];
        contentCell.selectionStyle = UITableViewCellSelectionStyleNone;
        contentCell.title = self.titleArray[indexPath.row];
        NSString *key = self.keyArray[indexPath.row];
        contentCell.content = LGNSString(self.dataDic[key]);
        return contentCell;
    }else if (indexPath.section == 1){
        //支架信息
        LGReportHolderCell *holderCell = [tableView dequeueReusableCellWithIdentifier:@"holderCell" forIndexPath:indexPath];
        holderCell.selectionStyle = UITableViewCellSelectionStyleNone;
        holderCell.dataDic = self.holderArray[indexPath.row];
        return holderCell;
    }else{
        LGReportDetailFileCell *fileCell = [tableView dequeueReusableCellWithIdentifier:@"fileCell" forIndexPath:indexPath];
        fileCell.selectionStyle = UITableViewCellSelectionStyleNone;
        fileCell.title = [NSString stringWithFormat:@"%@.pdf",self.dataDic[@"report_name"]];
        [fileCell.checkBtn addTarget:self action:@selector(checkFileInformation:) forControlEvents:UIControlEventTouchUpInside];
        return fileCell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1 && self.holderArray.count>0){
        return viewPix(99);
    }else if (section == 2){
        return viewPix(50);
    }
    return 0.1;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(section == 1 && self.holderArray.count>0){
        LGReportHolderHeaderView *headView = [[LGReportHolderHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(99))];
        return headView;
        
    }else if(section == 2){
        LGCornerHeaderView *headView = [[LGCornerHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(50))];
        headView.backgroundColor = [UIColor clearColor];
        headView.topMargin = viewPix(8);
        UIButton *titleBtn = [UIButton buttonWithTitle:@"报告原文件" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#1F6CC6" imageName:@""];
        titleBtn.frame = CGRectMake(viewPix(16), viewPix(20), 112, 27);
        [titleBtn setBackgroundImage:[UIImage imageNamed:@"就诊检查-蓝色"] forState:UIControlStateNormal];
        [headView addSubview:titleBtn];
        return headView;
    }else{
        UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.1)];
        return headView;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 1 && self.holderArray.count>0){
        return viewPix(31);
    }else if (section == 2){
        return viewPix(16);
    }
    return 0.1;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 1 && self.holderArray.count>0){
        LGReportHolderFooterView *footerView = [[LGReportHolderFooterView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(31))];
        return footerView;
        
    }else if(section == 2){
        LGCornerFooterView *footView = [[LGCornerFooterView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(16))];
        footView.backgroundColor = [UIColor clearColor];
        footView.bottomMargin = viewPix(8);
        return footView;
    }else{
        UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.1)];
        return footView;
    }
}



-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGReportDetailContentCell class] forCellReuseIdentifier:@"contentCell"];
        [_tableView registerClass:[LGReportDetailFileCell class] forCellReuseIdentifier:@"fileCell"];
        [_tableView registerClass:[LGReportHolderCell class] forCellReuseIdentifier:@"holderCell"];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    }
    return _tableView;
}



@end
